package com.hbnu.boot.config;

//import com.alibaba.druid.FastsqlException;

import com.hbnu.boot.bean.Cat;
import com.hbnu.boot.bean.Dog;
import com.hbnu.boot.bean.User;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cglib.reflect.FastClass;
import org.springframework.context.annotation.Bean;

/**
 * @Auther: hjx
 * @Date: 2023/6/12 14:31
 * @Description:
 */
//@ConditionalOnMissingClass(value = "com.alibaba.druid.FastsqlException")  //放在类级别，如果注解判断生效，则整个配置类才生效
@SpringBootConfiguration
public class AppConfig2 {
    //    @ConditionalOnClass(FastsqlException.class)
    @ConditionalOnClass(name = "com.alibaba.druid.FastsqlException")    //放在方法级别，单独对这个方法进行注解判断
    @Bean
    public Cat cat01() {
        return new Cat();
    }

    @ConditionalOnMissingClass(value = "com.alibaba.druid.FastsqlException")
    @Bean
    public Dog dog01() {
        return new Dog();
    }

//    @ConditionalOnBean(name = "cat01")
    @ConditionalOnBean(value = Dog.class)   //和上方两个注解意义相同
    @Bean
    public User zhangsan() {
        return new User();
    }

    @ConditionalOnMissingBean(name = "dog01")
    @Bean
    public User lisi() {
        return new User();
    }
}

